﻿namespace ScrumLite.Services.Tests
{
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using ScrumLite.Services.Contracts;
    using Rhino.Mocks;
    using System.Linq;
    using System.Collections.ObjectModel;

    [TestClass]
    public class LinqProjectsServiceFixture
    {
        MockRepository mocks;

        [TestInitialize]
        public void Initialize()
        {
            this.mocks = new MockRepository();
        }

        [TestMethod()]
        public void ShouldGetProjects()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();           
            ScrumLite.Data.Project[] expected = new ScrumLite.Data.Project[] { 
                new ScrumLite.Data.Project { id = Guid.NewGuid(), name = "Project 1", startsOn = new DateTime(2008,01,01), endsOn = new DateTime(2008,12,31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1", uri_projectSpecificMetrics = "http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/bb-project1" },
                new ScrumLite.Data.Project { id = Guid.NewGuid(), name = "Project 2", startsOn = new DateTime(2008,01,01), endsOn = new DateTime(2008,12,31), uri_repository = "http://svnrepo.scrumlite.org/bb-project2", security_group = "Group2", uri_projectSpecificMetrics = "http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/bb-project2" },
            };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProjects()).
                Callback(new Func<bool>( () => { return true; } )).Return(expected);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            Project[] actual = service.GetProjects();

            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i].id, actual[i].Id);
                Assert.AreEqual(expected[i].name, actual[i].Name);
                Assert.AreEqual(expected[i].startsOn, actual[i].StartsOn);
                Assert.AreEqual(expected[i].uri_repository, actual[i].RepositoryUri);
                Assert.AreEqual(expected[i].endsOn, actual[i].EndsOn);
                Assert.AreEqual(expected[i].security_group, actual[i].Group);
                Assert.AreEqual(expected[i].uri_projectSpecificMetrics, actual[i].ProjectSpecificMetricsUri);
            }                    
        }

        [TestMethod()]
        public void ShouldGetProjectName()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            Guid projectUri = Guid.NewGuid();
            ScrumLite.Data.Project expected = new ScrumLite.Data.Project { id = projectUri, name = "Project 1", startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1" };
            
            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProject(projectUri)).
                Callback(new Func<Guid, bool>(r => { return true; })).Return(expected);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            string actual = service.GetProjectName(projectUri.ToString());

            Assert.AreEqual(expected.name, actual);
        }

        [TestMethod()]
        public void ShouldGetProject()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            Guid projectUri = Guid.NewGuid();
            ScrumLite.Data.Project expected = new ScrumLite.Data.Project { id = projectUri, name = "Project 1", startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1" };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProject(Guid.Empty))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            Project actual = service.GetProject(projectUri.ToString());

            Assert.AreEqual(expected.id, actual.Id);
            Assert.AreEqual(expected.uri_projectSpecificMetrics, actual.ProjectSpecificMetricsUri);
            Assert.AreEqual(expected.uri_repository, actual.RepositoryUri);
            Assert.AreEqual(expected.security_group, actual.Group);
            Assert.AreEqual(expected.startsOn, actual.StartsOn);
            Assert.AreEqual(expected.endsOn, actual.EndsOn);
        }

        [TestMethod()]
        public void ShouldGetProjectByName()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            string projectName = "test";
            ScrumLite.Data.Project expected = new ScrumLite.Data.Project { id = Guid.NewGuid(), name = projectName, startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1" };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProjectByName(projectName))
                .Return(expected)
                .Callback(new Func<string, bool>(r => { return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            Project actual = service.GetProjectByName(projectName);

            Assert.AreEqual(expected.id, actual.Id);
            Assert.AreEqual(expected.uri_projectSpecificMetrics, actual.ProjectSpecificMetricsUri);
            Assert.AreEqual(expected.uri_repository, actual.RepositoryUri);
            Assert.AreEqual(expected.security_group, actual.Group);
            Assert.AreEqual(expected.startsOn, actual.StartsOn);
            Assert.AreEqual(expected.endsOn, actual.EndsOn);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void GetProjectThrowsIfNotExists()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProject(Guid.Empty)).Return(null);
                //.Callback(new Func<Guid, bool>(r => { return true; }));//.Return(expected);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);
            service.GetProject(Guid.NewGuid().ToString());
        }
        
        [TestMethod()]
        public void ShouldGetProjectRepository()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            Guid projectUri = Guid.NewGuid();
            string projectRepository = "http://svnrepo.scrumlite.org/bb-project1";
            ScrumLite.Data.Project expected = new ScrumLite.Data.Project { id = projectUri, name = "Project 1", startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = projectRepository, security_group = "Group1" };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProject(projectUri)).
                Callback(new Func<Guid, bool>(r => { return true; })).Return(expected);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            string actual = service.GetProjectRepository(projectUri.ToString());

            Assert.AreEqual(expected.uri_repository, actual);
        }

        [TestMethod()]
        public void ShouldGetUriProjectSpecificMetrics()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            Guid projectUri = Guid.NewGuid();
            string uriProjectSpecificMetrics = "http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/bb-project1";
            ScrumLite.Data.Project expected = new ScrumLite.Data.Project { id = projectUri, name = "Project 1", startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1", uri_projectSpecificMetrics = uriProjectSpecificMetrics };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetProject(projectUri)).
                Callback(new Func<Guid, bool>(r => { return true; })).Return(expected);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            string actual = service.GetUriProjectSpecificMetrics(projectUri.ToString());

            Assert.AreEqual(expected.uri_projectSpecificMetrics, actual);
        }

        [TestMethod()]
        public void ShouldAddProject()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            ScrumLite.Data.Project actual = null;

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(() => store.Add(null))
                .Callback(new Func<ScrumLite.Data.Project, bool>(p => { actual = p; return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            Project expected = new Project { Id = Guid.NewGuid(),Name="YellowStone", StartsOn= DateTime.Today, EndsOn=DateTime.Today.AddDays(1),RepositoryUri="http://svnrepo.scrumlite.org", ProjectSpecificMetricsUri="http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/Yellowstone" };
            service.Add(expected);

            Assert.AreEqual(expected.Id, actual.id);
            Assert.AreEqual(expected.Name, actual.name);
            Assert.AreEqual(expected.StartsOn, actual.startsOn);
            Assert.AreEqual(expected.EndsOn, actual.endsOn);
            Assert.AreEqual(expected.RepositoryUri, actual.uri_repository.ToString());
            Assert.AreEqual(expected.ProjectSpecificMetricsUri, actual.uri_projectSpecificMetrics.ToString());
        }

        [TestMethod()]
        public void ShouldUpdateProject()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            Guid projectId = Guid.NewGuid();
            ScrumLite.Data.Project actual = new ScrumLite.Data.Project() { id = projectId, endsOn = DateTime.Today, name = "ScrumLite", startsOn = DateTime.Today, uri_repository = "http://svnrepo.scrumlite.org", uri_projectSpecificMetrics = "http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/Yellowstone" };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(() => store.Update(null))
                .Callback(new Func<ScrumLite.Data.Project, bool>(p => { actual = p; return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            Project expected = new Project { Id = projectId, Name = "YellowStone", StartsOn = DateTime.Today, EndsOn = DateTime.Today.AddDays(1), RepositoryUri = "http://svnrepo.scrumlite.org", ProjectSpecificMetricsUri = "http://xdelacroix.swcorpnet.ad/ccnet/server/local/project/Yellowstone" };
            service.Update(expected);

            Assert.AreEqual(expected.Id, actual.id);
            Assert.AreEqual(expected.Name, actual.name);
            Assert.AreEqual(expected.StartsOn, actual.startsOn);
            Assert.AreEqual(expected.EndsOn, actual.endsOn);
            Assert.AreEqual(expected.RepositoryUri, actual.uri_repository.ToString());
            Assert.AreEqual(expected.ProjectSpecificMetricsUri, actual.uri_projectSpecificMetrics.ToString());
        }

        [TestMethod()]
        public void ShouldReturnProjectPersons()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            Guid projectPersonId = Guid.NewGuid();
            Guid projectUri = Guid.NewGuid();
            Guid roleId = Guid.NewGuid();

             List<ScrumLite.Data.Role> roleList = new List<ScrumLite.Data.Role>();
             roleList.Add(new ScrumLite.Data.Role() { 
                    id= roleId, 
                    name = "test" 
                });

            Dictionary<ScrumLite.Data.ProjectPerson, List<ScrumLite.Data.Role>> expected = new Dictionary<ScrumLite.Data.ProjectPerson, List<ScrumLite.Data.Role>>();
            expected.Add ( new ScrumLite.Data.ProjectPerson() { 
                    fk_project = projectUri, 
                    isInternal = true, 
                    samAccountName = "southy", 
                    id = projectPersonId
                },roleList);

            ScrumLite.Data.Project expectedProject = new ScrumLite.Data.Project()
            {
                id = projectUri,
                name = "projectTest"
            };
            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetPeople(projectUri))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetProject(projectUri))
                .Return(expectedProject)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            PersonAssignation[] actual = service.GetPersonsInProject(projectUri.ToString());

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Length);
            Assert.AreEqual(expected.First().Key.isInternal, actual[0].IsInternal);
            Assert.AreEqual(expected.First().Key.fk_project, actual[0].Project.Id);
            Assert.AreEqual(expectedProject.name, actual[0].Project.Name);
            Assert.AreEqual(expected.First().Value.Count(), actual[0].Roles.Count());
            Assert.AreEqual(expected.First().Value.First().id, actual[0].Roles[0].Id);
            Assert.AreEqual(expected.First().Value.First().name, actual[0].Roles[0].Name);
        }

        [TestMethod()]
        public void ShouldReturnCheckList()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            Guid projectUri = Guid.NewGuid();
            Dictionary<string, string[]> expected = new Dictionary<string, string[]>();
            expected.Add("WorkAreas", new string[1] { "error1" });
            ScrumLite.Data.Project project = new ScrumLite.Data.Project { id = projectUri, name = "Project 1", startsOn = new DateTime(2008, 01, 01), endsOn = new DateTime(2008, 12, 31), uri_repository = "http://svnrepo.scrumlite.org/bb-project1", security_group = "Group1" };

            Dictionary<string, Collection<ScrumLite.Data.ComplianceChecker>> expectedChecker = ReturnCheckers();

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.CheckProjectCompliance(projectUri))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetProject(projectUri))
                .Return(project)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetComplianceCheckerProperties())
                .Return(expectedChecker);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            CheckStatus[] actual = service.CheckCompliance(projectUri.ToString());

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual(expected.First().Key.Trim(), actual[0].PropertyChecked.Trim());
            Assert.IsFalse(actual[0].Status);
            Assert.AreEqual(expected.First().Value.Count(), actual[0].Errors.Count());
            Assert.AreEqual(expected.First().Value.First().Trim(), actual[0].Errors[0].Trim());
            Assert.AreEqual("SVN Repository has all the required records", actual[1].PropertyChecked.Trim());
        }

        [TestMethod()]
        public void ShouldReturnCheckListWithoutExcludedDates()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            Guid projectUri = Guid.NewGuid();
            Dictionary<string, string[]> expected = new Dictionary<string, string[]>();
            expected.Add("WorkAreas", new string[1] { "error1" });
            ScrumLite.Data.Project project = new ScrumLite.Data.Project { id = projectUri, name = "Project ScrumLite", startsOn = new DateTime(2008, 03, 01), endsOn = new DateTime(2008, 05, 02), uri_repository = "http://svnrepo.scrumlite.org/ScrumLite-v2", security_group = "Group1" };

            Dictionary<string, Collection<ScrumLite.Data.ComplianceChecker>> expectedChecker = ReturnCheckers();

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.CheckProjectCompliance(projectUri))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetProject(projectUri))
                .Return(project)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetComplianceCheckerProperties())
                .Return(expectedChecker);
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            CheckStatus[] actual = service.CheckCompliance(projectUri.ToString());

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual(expected.First().Key.Trim(), actual[0].PropertyChecked.Trim());
            Assert.IsFalse(actual[0].Status);
            Assert.AreEqual(expected.First().Value.Count(), actual[0].Errors.Count());
            Assert.AreEqual(expected.First().Value.First().Trim(), actual[0].Errors[0].Trim());
            Assert.AreEqual("SVN Repository has all the required records", actual[1].PropertyChecked.Trim());
            Assert.IsFalse(actual[1].Errors.Contains("generico/2008w14/20080402EOD.msg"));
        }

        private static Dictionary<string, Collection<ScrumLite.Data.ComplianceChecker>> ReturnCheckers()
        {
            Dictionary<string, Collection<ScrumLite.Data.ComplianceChecker>> expectedChecker = new Dictionary<string, Collection<ScrumLite.Data.ComplianceChecker>>();

            /*Compliance Checkers*/
            ScrumLite.Data.ComplianceChecker check1 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "GenericProcessFolder", value = "generico", notes = null };
            ScrumLite.Data.ComplianceChecker check2 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "ReviewsFolderName", value = "reviews", notes = null };
            ScrumLite.Data.ComplianceChecker check3 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "WeekFolderName", value = "{0}w{1}", notes = null };
            ScrumLite.Data.ComplianceChecker check4 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "DevelopmentFolderName", value = "desarrolloAMedida", notes = null };
            ScrumLite.Data.ComplianceChecker check5 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "WeeklyProcessLocation", value = "{0}/{1}", notes = null };
            ScrumLite.Data.ComplianceChecker check6 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "DailyProcessLocation", value = "{0}/{1}/{2}", notes = null };
            ScrumLite.Data.ComplianceChecker check7 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "ReviewProcessLocation", value = "{0}/{1}/{2}", notes = null };
            ScrumLite.Data.ComplianceChecker check8 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "DevelopmentProcessLocation", value = "{0}/{1}", notes = null };
            ScrumLite.Data.ComplianceChecker check9 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "SOIFileName", value = "{0}w{1}SOI.msg", notes = null };
            ScrumLite.Data.ComplianceChecker check10 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "EOIFileName", value = "{0}w{1}EOI.msg", notes = null };
            ScrumLite.Data.ComplianceChecker check11 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2008, 04, 10), property = "ReviewFileName", value = "iterationW{0}Review.pptx", notes = null };
            ScrumLite.Data.ComplianceChecker check12 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "EODFileName", value = "{0}EOD.msg", notes = null };
            ScrumLite.Data.ComplianceChecker check13 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "SODFileName", value = "{0}SOD.msg", notes = null };
            ScrumLite.Data.ComplianceChecker check14 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "UseCaseDiagramFileName", value = "useCaseDiagram.pptx", notes = null };
            ScrumLite.Data.ComplianceChecker check15 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "UserStoriesFileName", value = "userStories.docx", notes = null };
            ScrumLite.Data.ComplianceChecker check16 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "DeploymentDiagramFileName", value = "deploymentDiagram.pptx", notes = null };
            ScrumLite.Data.ComplianceChecker check17 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "ArchitectureDiagramFileName", value = "architectureDiagram.pptx", notes = null };
            ScrumLite.Data.ComplianceChecker check18 = new ScrumLite.Data.ComplianceChecker { id = Guid.NewGuid(), dateBegin = new DateTime(2007, 01, 01), property = "DevelopmentEnvironmentFileName", value = "developmentEnvironment.txt", notes = null };

            /*Arrays*/
            expectedChecker.Add("GenericProcessFolder", new Collection<ScrumLite.Data.ComplianceChecker> { check1 });
            expectedChecker.Add("ReviewsFolderName", new Collection<ScrumLite.Data.ComplianceChecker> { check2 });
            expectedChecker.Add("WeekFolderName", new Collection<ScrumLite.Data.ComplianceChecker> { check3 });
            expectedChecker.Add("DevelopmentFolderName", new Collection<ScrumLite.Data.ComplianceChecker> { check4 });
            expectedChecker.Add("WeeklyProcessLocation", new Collection<ScrumLite.Data.ComplianceChecker> { check5 });
            expectedChecker.Add("DailyProcessLocation", new Collection<ScrumLite.Data.ComplianceChecker> { check6 });
            expectedChecker.Add("ReviewProcessLocation", new Collection<ScrumLite.Data.ComplianceChecker> { check7 });
            expectedChecker.Add("DevelopmentProcessLocation", new Collection<ScrumLite.Data.ComplianceChecker> { check8 });
            expectedChecker.Add("SOIFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check9 });
            expectedChecker.Add("EOIFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check10 });
            expectedChecker.Add("ReviewFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check11 });
            expectedChecker.Add("EODFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check12 });
            expectedChecker.Add("SODFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check13 });
            expectedChecker.Add("UseCaseDiagramFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check14 });
            expectedChecker.Add("UserStoriesFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check15 });
            expectedChecker.Add("DeploymentDiagramFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check16 });
            expectedChecker.Add("ArchitectureDiagramFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check17 });
            expectedChecker.Add("DevelopmentEnvironmentFileName", new Collection<ScrumLite.Data.ComplianceChecker> { check18 });            

            return expectedChecker;
        }

        [TestMethod()]
        public void ShouldReturnComplianceCheckSVNFromStartDateToCurrentDate()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            Guid projectUri = Guid.NewGuid();
            Dictionary<string, string[]> expected = new Dictionary<string, string[]>();
            expected.Add("WorkAreas", new string[1] { "error1" });
            ScrumLite.Data.Project project = new ScrumLite.Data.Project { id = projectUri, name = "Project ScrumLite", startsOn = new DateTime(2008, 03, 01), endsOn = DateTime.Now.AddDays(30), uri_repository = "http://svnrepo.scrumlite.org/ScrumLite-v2", security_group = "Group1" };

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.CheckProjectCompliance(projectUri))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetProject(projectUri))
                .Return(project)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            CheckStatus[] actual = service.CheckCompliance(projectUri.ToString());

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual(expected.First().Key.Trim(), actual[0].PropertyChecked.Trim());
            Assert.IsFalse(actual[0].Status);
            Assert.AreEqual(expected.First().Value.Count(), actual[0].Errors.Count());
            Assert.AreEqual(expected.First().Value.First().Trim(), actual[0].Errors[0].Trim());
            Assert.AreEqual("SVN Repository has all the required records", actual[1].PropertyChecked.Trim());
            Assert.AreEqual(0, actual[1].Errors.Count());
        }

        [TestMethod()]
        public void ShouldAddPersonToProject()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            ScrumLite.Data.ProjectPerson actual = null;
            List<ScrumLite.Data.ProjectPersonRole> roles = new List<ScrumLite.Data.ProjectPersonRole>();

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(() => store.AddPerson(null))
                .Callback(new Func<ScrumLite.Data.ProjectPerson, bool>(p => { actual = p; return true; }));
            Expect.Call(() => store.AddPersonRole(null))
                .Callback(new Func<ScrumLite.Data.ProjectPersonRole, bool>(p => { roles.Add(p); return true; }));
            Expect.Call(() => store.AddPersonRole(null))
                .Callback(new Func<ScrumLite.Data.ProjectPersonRole, bool>(p => { roles.Add(p); return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            string personId = "member";
            Guid projectUri = Guid.NewGuid();
            Guid roleId1 = Guid.NewGuid();
            Guid roleId2 = Guid.NewGuid();

            TeamMember member = new TeamMember(new Collection<string> { roleId1.ToString(), roleId2.ToString() }) { ProjectId = projectUri.ToString(), IsInternal = false, PersonId = personId.ToString() };

            service.AddPersonToProject(projectUri.ToString(), member);

            Assert.IsNotNull(actual);
            Assert.AreEqual(personId, actual.samAccountName);
            Assert.AreEqual(projectUri, actual.fk_project);
            Assert.IsFalse(actual.isInternal);
            Assert.AreEqual(2, roles.Count);
            Assert.AreEqual(actual.id, roles[0].fk_projectPerson);
            Assert.AreEqual(actual.id, roles[1].fk_projectPerson);
            Assert.AreEqual(roleId1, roles[0].fk_role);
            Assert.AreEqual(roleId2, roles[1].fk_role);
        }

        [TestMethod()]
        public void ShouldRemovePersonFromProject()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();
            string actual = "";
            Guid projectId = Guid.NewGuid();
            string personId = "member";

            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(() => store.RemovePerson(projectId,personId))
                 .Callback(new Func<Guid, string, bool>((p,r) => {actual = r; return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            service.RemovePersonFromProject(projectId.ToString(), personId);

            Assert.AreEqual(actual, personId);
        }

        [TestMethod()]
        public void ShouldReturnNullProjectPersons()
        {
            ScrumLite.Data.IProjectStore store = this.mocks.DynamicMock<ScrumLite.Data.IProjectStore>();

            Guid projectUri = Guid.NewGuid();

            Dictionary<ScrumLite.Data.ProjectPerson, List<ScrumLite.Data.Role>> expected = new Dictionary<ScrumLite.Data.ProjectPerson,List<ScrumLite.Data.Role>>();

            ScrumLite.Data.Project expectedProject = new ScrumLite.Data.Project()
            {
                id = projectUri,
                name = "projectTest"
            };
            // set an expectation that will do a callback and set the argument 
            // to a local member to perform Asserts later
            Expect.Call(store.GetPeople(projectUri))
                .Return(expected)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            Expect.Call(store.GetProject(projectUri))
                .Return(expectedProject)
                .Callback(new Func<Guid, bool>(r => { return true; }));
            mocks.ReplayAll();

            LinqProjectsService service = new LinqProjectsService(store);

            PersonAssignation[] actual = service.GetPersonsInProject(projectUri.ToString());

            Assert.IsNull(actual);
        }

    }
}
